//
//  AppDelegate.m
//  LearnTeacher
//
//  Created by zyl_macbookpro on 2024/4/9.
//

#import "AppDelegate.h"
#import "LTMineViewController.h"
#import "LTLoginViewController.h"
#import "MJTabBarController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.loginInfo? [self goHome]:[self goLogin];
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)goHome
{
    self.window.rootViewController = [[MJTabBarController alloc] init];
}
- (void)goLogin
{
    USER_DEFAULTS_REMOVE_OBJECT_FOR_KEY(USER_LOGIN_INFO);
    LTBaseNavigationController *nav = [[LTBaseNavigationController alloc] initWithRootViewController:[LTLoginViewController new]];
    self.window.rootViewController = nav;
}
- (NSString *)token
{
  
    return self.loginInfo[@"token"];
}
- (NSString *)mobile
{
    return self.loginInfo[@"mobile"];
}
- (NSDictionary *)loginInfo
{
    NSString *jsonString = USER_DEFAULTS_VALUE_FOR_KEY(USER_LOGIN_INFO);
    NSDictionary *dictionary = nil;
    if (jsonString.length > 0) {
        NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error = nil;
        dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
         
    }
    return dictionary;
}
@end
